using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using idea.entity;

namespace pos
{
    public partial class PayFrmConfirm : Form
    {
        public PayFrmConfirm()
        {
            InitializeComponent();
        }
        private double m_sumMoney;
        public double sumMoney
        {
            set
            {
                m_sumMoney = value;
            }
        }
        public double payMoney
        {
            get
            {
                return Convert.ToDouble(ss.Text);
            }
        }

        private void PayFrmConfirm_Load(object sender, EventArgs e)
        {
            ys.Text = m_sumMoney.ToString();

        }
        private bool checkSubmit()
        {
            if (ss.Text == "")
                return false;
            try
            {
                double payMoney = Convert.ToDouble(ss.Text);
                if (zl.Text == "")
                {
                    double c = payMoney - m_sumMoney; ;
                    zl.Text = string.Format("{0:F2}", c);
                    return false;
                }

                double changeMoney = payMoney - m_sumMoney; ;
                double changeMoney1 = Convert.ToDouble(zl.Text);
                if ((long)((changeMoney1 + 0.00001) * 1000) != (long)((changeMoney + 0.00001) * 1000))
                {
                    double c = payMoney - m_sumMoney; ;
                    zl.Text = string.Format("{0:F2}", c);
                    return false;
                }
                if (changeMoney < 0)
                    return false;
                else
                    return true;

               
            }
            catch
            {
                return false;
            }
        }
        private void ss_KeyPress(object sender, KeyPressEventArgs e)
        {

            if (e.KeyChar == (char)Keys.Enter)
            {
                if (checkSubmit())
                    submit();
            }

        }
        private void submit()
        {
            this.DialogResult = DialogResult.Yes;
            this.Close();
        }

        private void cmdOK_Click(object sender, EventArgs e)
        {

            if (checkSubmit())
                submit();
            else
            {
                ss.SelectAll();
                
            }

        }

    }
}